package com.qiongyou.helper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateHelper {
	public static String getStringFromDate(Date date, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		String str = sdf.format(date);// 将Date格式化为String
		return str;
	}

	public static Date getDateFromStr(String str, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		Date date = null;
		try {
			date = sdf.parse(str);//String解析成Date
		} catch (ParseException e) {
			System.out.println("数据源有误，解析失败");

		}
		return date;
	}
}
